#include "stdafx.h"
#include "TestFiles.h"

#include <atlconv.h>


const wchar_t * const TestFiles::UnitTestPluginDirwStr = L"..\\..\\..\\ThirdPartyLibs\\";
const char    * const TestFiles::UnitTestPluginDirStr = "..\\..\\..\\ThirdPartyLibs\\";

const wchar_t * const TestFiles::UnitTestIEFwStr = L"..\\..\\..\\UnitTestData\\Test.ief";
const char *	const TestFiles::UnitTestIEFStr = "..\\..\\..\\UnitTestData\\Test.ief";
const wchar_t * const TestFiles::UnitTestIEFTemplatewStr = L"..\\..\\..\\UnitTestData\\Template.ief";
const char *	const TestFiles::UnitTestIEFTemplateStr = "..\\..\\..\\UnitTestData\\Template.ief";
const wchar_t * const TestFiles::UnitTestCopyFilewStr = L"..\\..\\..\\UnitTestData\\Copy.ief";
const wchar_t * const TestFiles::UnitTestIDFwStr = L"..\\..\\..\\UnitTestData\\Test.idf";
const wchar_t * const TestFiles::UnitTestIntermediateImageFilewStr = L"..\\..\\..\\UnitTestData\\MustBePresent.bmp";
const char    * const TestFiles::UnitTestIntermediateImageFileStr = "..\\..\\..\\UnitTestData\\MustBePresent.bmp";
const wchar_t * const TestFiles::UnitTestImageDirwStr = L"..\\..\\..\\UnitTestData";
const wchar_t * const TestFiles::UnitTestImagePathFilenamewStr = L"..\\..\\..\\UnitTestData\\MustBePresentImage.bmp";
const char *    const TestFiles::UnitTestImagePathFilenameStr = "..\\..\\..\\UnitTestData\\MustBePresentImage.bmp";
const char    * const TestFiles::UnitTestImageStr = "MustBePresentImage";


TestFiles::TestFiles(void) 
{
	_szDirectory[0] = 0;
	_szThirdPartyLibs[0] = 0;
	_plugins = 0;
}

TestFiles::~TestFiles(void)
{
	if (_plugins != 0 )
		delete _plugins;
	_plugins = 0;
}

const wchar_t * TestFiles::GetThirdPartyLibFolder() 
{ 
	const wchar_t *rc = L"invalid folder";

	if (_szThirdPartyLibs[0] != 0)
		rc = _szThirdPartyLibs;
	else
	{
		if(::GetCurrentDirectory((sizeof(_szDirectory) - 1)/sizeof(TCHAR), _szDirectory))
		{
			if (::PathCombine(_szThirdPartyLibs, _szDirectory, TestFiles::UnitTestPluginDirwStr) != NULL)
			{
				rc = _szThirdPartyLibs;
			}
		}
	}
	return rc;
}

MxPluginLibs*  TestFiles::GetPluginLibs(std::wstring *errorMsg)
{
	if ( (_plugins == 0) && (errorMsg != 0))
	{
		_plugins = new MxPluginLibs();
		std::string errMsg;
		if (MxPluginLibs::InitPlugins(_plugins, &errMsg, TestFiles::Instance().GetThirdPartyLibFolder()) == false) 
		{
			USES_CONVERSION; 
#pragma warning(suppress: 6255)
			*errorMsg = A2CW(errMsg.c_str());
			delete _plugins;
			_plugins = 0;
		}
	}
	return _plugins;
}

